<?php
/***************************************************************************
*                            Dolphin Smart Community Builder
*                              -------------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2007 BoonEx Notice
*     website              : http://www.boonex.com
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or  any later version.
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/

bx_import ('BxDolProfileFields');
bx_import ('BxDolFormMedia');

class BxNoticesFormAdd extends BxDolFormMedia {

    var $_oMain, $_oDb;

    function BxNoticesFormAdd ($oMain, $iProfileId, $iEntryId = 0, $iThumb = 0) {

        $this->_oMain = $oMain;
        $this->_oDb = $oMain->_oDb;
  
  		$sDefaultTitle = stripslashes($_REQUEST['title']);
 
 		$aPeriods = $this->_oDb->getrecurring_periods();
		$aCount = $this->_oDb->getRecurringCount(1,100);
 
		require_once(BX_DIRECTORY_PATH_INC . 'membership_levels.inc.php');
		$aMemberships = getMemberships ();
		unset ($aMemberships[MEMBERSHIP_ID_NON_MEMBER]); // unset Non-member
		$aMemberships = array('' => _t('_modzzz_notices_membership_filter_none')) + $aMemberships;
  
        $oProfileFields = new BxDolProfileFields(0);
        $aCountries = $oProfileFields->convertValues4Input('#!Country');
        asort($aCountries);

		if($_POST['country']){
			$sSelCountry = $_POST['country'];
		}else{
			$sSelCountry = getParam('modzzz_notices_default_country');
		}

        $aCompensation = $oProfileFields->convertValues4Input('#!NoticesCompensation');
        ksort($aCompensation);


        // generate templates for custom form's elements
        $aCustomMediaTemplates = $this->generateCustomMediaTemplates ($oMain->_iProfileId, $iEntryId, $iThumb);

        // privacy

         $aInputPrivacyCustomPass = array (
            'pass' => 'Preg', 
            'params' => array('/^([0-9f]+)$/'),
        );
 
        $aInputPrivacyComment = $this->_oMain->_oPrivacy->getGroupChooser($iProfileId, 'notices', 'comment');
        $aInputPrivacyComment['values'] = $aInputPrivacyComment['values'];
        $aInputPrivacyComment['db'] = $aInputPrivacyCustomPass;

        $aInputPrivacyRate = $this->_oMain->_oPrivacy->getGroupChooser($iProfileId, 'notices', 'rate');
        $aInputPrivacyRate['values'] = $aInputPrivacyRate['values'];
        $aInputPrivacyRate['db'] = $aInputPrivacyCustomPass;
  
        $aCustomForm = array(

            'form_attrs' => array(
                'name'     => 'form_notices',
                'action'   => '',
                'method'   => 'post',
                'enctype' => 'multipart/form-data',
            ),      

            'params' => array (
                'db' => array(
                    'table' => 'modzzz_notices_main',
                    'key' => 'id',
                    'uri' => 'uri',
                    'uri_title' => 'title',
                    'submit_name' => 'submit_form',
                ),
            ),
                  
            'inputs' => array(

                'header_info' => array(
                    'type' => 'block_header',
                    'caption' => _t('_modzzz_notices_form_header_info')
                ), 
				'category' => array(
                    'type' => 'select',
                    'name' => 'category',
                    'caption' => _t('_modzzz_notices_form_caption_category'),
					'values' => array(
								'travel'=>_t('_modzzz_notices_travel'), 
								'available'=>_t('_modzzz_notices_availability')
							  ),
                    'required' => false,  
					'db' => array (
                        'pass' => 'Xss', 
                    ),
                 ),
                'title' => array(
                    'type' => 'text',
                    'name' => 'title',
                    'caption' => _t('_modzzz_notices_form_caption_title'),
                    'value' => $sDefaultTitle,
                    'required' => true,
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(3,$this->_oMain->_oConfig->getTitleLength()),
                        'error' => _t ('_modzzz_notices_form_err_title'),
                    ),
                    'db' => array (
                        'pass' => 'Xss', 
                    ),
                ),    
                'snippet' => array(
                    'type' => 'textarea',
                    'html' => 0,
                    'name' => 'snippet',
                    'caption' => _t("_td_snippet"),
                    'value' => '',
                	'required' => 1,
                    'checker' => array (  
                        'func' => 'length',
                        'params' => array(3, $this->_oMain->_oConfig->getSnippetLength()),
                        'error' => _t('_modzzz_notices_form_info_snippet', $this->_oMain->_oConfig->getSnippetLength()),
                    ),                    
                    'db' => array (
                        'pass' => 'Xss',
                    ),
                ),	 
                'desc' => array(
                    'type' => 'textarea',
                    'name' => 'desc',
                    'caption' => _t('_modzzz_notices_form_caption_desc'),
                    'required' => true,
                    'html' => 2,
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(20,64000),
                        'error' => _t ('_modzzz_notices_form_err_desc'),
                    ),                    
                    'db' => array (
                        'pass' => 'XssHtml', 
                    ),                    
                ), 
				'country' => array(
                    'type' => 'select',
                    'name' => 'country',
                    'listname' => 'Country', 
                    'caption' => _t('_modzzz_notices_form_caption_country'),
                    'values' => $aCountries,
 					'value' => $sSelCountry,
                    'required' => false,  
                    'db' => array (
                        'pass' => 'Preg', 
                        'params' => array('/([a-zA-Z]{2})/'),
                    ),
					'display' => 'getPreListDisplay', 
                ),
                'city' => array(
                    'type' => 'text',
                    'name' => 'city',
                    'caption' => _t('_modzzz_notices_form_caption_city'),
                    'required' => false, 
                    'db' => array (
                        'pass' => 'Xss', 
                    ),
                    'display' => true,
                ),  
                'start' => array(
                    'type' => 'datetime',
                    'name' => 'start',
                    'caption' => _t("_modzzz_notices_form_caption_from"),
                    'value' => date('Y-m-d H:i:00'),
                	'required' => 1,
                    'checker' => array (  
                        'func' => 'DateTime',
                        'error' => _t('_td_err_empty_value'),
                    ),                    
                    'db' => array (
                        'pass' => 'DateTime', 
                    ),
                ), 
                'end' => array(
                    'type' => 'datetime',
                    'name' => 'end',
                    'caption' => _t("_modzzz_notices_form_caption_to"),
                    'value' => date('Y-m-d H:i:00'),
                	'required' => 1,
                    'checker' => array (  
                        'func' => 'DateTime',
                        'error' => _t('_td_err_empty_value'),
                    ),                    
                    'db' => array (
                        'pass' => 'DateTime', 
                    ),
                ),
                'compensation' => array(
                    'type' => 'select',
                    'name' => 'compensation',
                    'listname' => 'NoticesCompensation', 
                    'values' => $aCompensation,
                    'caption' => _t('_modzzz_notices_form_caption_compensation'),
                    'required' => false, 
                    'db' => array (
                        'pass' => 'Int', 
                    ),
					'display' => 'getPreListDisplay', 
                ),
                'tags' => array(
                    'type' => 'text',
                    'name' => 'tags',
                    'caption' => _t('_Tags'),
                    'info' => _t('_sys_tags_note'),
                    'required' => true,
                    'checker' => array (
                        'func' => 'avail',
                        'error' => _t ('_modzzz_notices_form_err_tags'),
                    ),
                    'db' => array (
                        'pass' => 'Tags', 
                    ), 
                ),   
				'publish' => array(
                    'type' => 'select',
                    'name' => 'publish',
                    'caption' => _t('_modzzz_notices_form_caption_publish_now'),
                    'info' => _t('_modzzz_notices_form_info_publish_now'),
					'values' => array(1=>_t('_Yes'), 0=>_t('_No')),
                    'required' => false,  
					'db' => array (
                        'pass' => 'Int',  
                    ),
                 ),  
                'when' => array(
                    'type' => 'datetime',
                    'name' => 'when',
                    'caption' => _t("_modzzz_notices_form_caption_publish_date"),
                    'value' => date('Y-m-d H:i:00'),
                	'required' => 1,
                    'checker' => array (  
                        'func' => 'DateTime',
                        'error' => _t('_td_err_empty_value'),
                    ),                    
                    'db' => array (
                        'pass' => 'DateTime', 
                    ),
                ),

				// recurring 
				'header_recurring' => array(
					'type' => 'block_header',
					'caption' => _t('_modzzz_notices_form_header_recurring'),
					'collapsable' => true,
					'collapsed' => false,
				),
				'recurring' => array(
					'type' => 'select',
					'name' => 'recurring',
					'caption' => _t('_modzzz_notices_caption_recurring'),
					'values' => array('no'=>_t('_modzzz_notices_recurring_no'),'yes'=>_t('_modzzz_notices_recurring_yes')),
					'required' => false, 
					'db' => array (
					'pass' => 'Xss', 
					),
				 ), 
				'recurring_num' => array(
					'type' => 'select',
					'name' => 'recurring_num',
					'caption' => _t('_modzzz_notices_caption_recurring_number'),
					'values' => $aCount,
							'required' => false, 
					'db' => array (
					'pass' => 'int', 
					),
				 ), 
				'recurring_period' => array(
					'type' => 'select',
					'name' => 'recurring_period',
					'caption' => _t('_modzzz_notices_caption_recurring_period'),
					'values' => $aPeriods,
							'required' => false, 
					'db' => array (
					'pass' => 'Xss', 
					),
				 ),
 
                // privacy
                
                'header_privacy' => array(
                    'type' => 'block_header',
                    'caption' => _t('_modzzz_notices_form_header_privacy'),
                ),

                'allow_view_notice_to' => $this->_oMain->_oPrivacy->getGroupChooser($iProfileId, 'notices', 'view_notice'),
  
                'allow_comment_to' => $aInputPrivacyComment,

                'allow_rate_to' => $aInputPrivacyRate, 
      
            ),            
        );

	    if(getParam('modzzz_notices_allow_pay')!='on')
		   unset($aCustomForm['inputs']['compensation']);

        $aFormInputsSubmit = array (
            'Submit' => array (
                'type' => 'submit',
                'name' => 'submit_form',
                'value' => _t('_Submit'),
                'colspan' => true,
            ),            
        );

        $aFormInputsAdminPart = array ();
        if ($GLOBALS['oBxNoticesModule']->isAdmin()) {

            require_once(BX_DIRECTORY_PATH_INC . 'membership_levels.inc.php');
            $aMemberships = getMemberships ();
            unset ($aMemberships[MEMBERSHIP_ID_NON_MEMBER]); // unset Non-member
            $aMemberships = array('' => _t('_modzzz_notices_membership_filter_none')) + $aMemberships;
            $aFormInputsAdminPart = array (
                'notice_membership_filter' => array(
                    'type' => 'select_box',
                    'name' => 'notice_membership_filter',
                    'caption' => _t('_modzzz_notices_caption_membership_filter'), 
                    'info' => _t('_modzzz_notices_info_membership_filter'), 
                    'values' => $aMemberships, 
                    'db' => array (
						'pass' => 'Categories' 
                    ),
                    'attrs' => array (
						'add_other' => false 
                    ),
	 
                ),
            );
        }
 
		$aCustomForm['inputs'] = array_merge($aCustomForm['inputs'], $aFormInputsAdminPart);
		$aCustomForm['inputs'] = array_merge($aCustomForm['inputs'], $aFormInputsSubmit);
 
        parent::BxDolFormMedia ($aCustomForm);
    }

}

?>
